﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Business.WPF;
using Presenters.WPF.Views;

namespace Presenters.WPF
{
    public class SearchStudentsPresenter
    {
        public ISearchStudentsView View { get; set; }

        public SearchStudentsPresenter(ISearchStudentsView view)
        {
            this.View = view;
        }
        public void SearchStudent()
        {
            if (this.View.isSearchByID == true)
                SearchStudentByID();

            if (this.View.isSearchByName == true)
                SearchStudentByName();
          
        }
        public void SearchStudentByName()
        {
            try
            {
                SearchStudentsManager ssm = new SearchStudentsManager();
                this.View.studentResults = ssm.SearchStudentsByName(this.View.searchTextBox);
            }
            catch (Exception ex)
            {
                this.View.message = "Error " + ex.Message;
            }
        }
        public void SearchStudentByID()
        {
            try
            {
                SearchStudentsManager ssm = new SearchStudentsManager();
                this.View.studentResults = ssm.SearchStudentsByID(this.View.searchTextBox);
            }
            catch (Exception ex)
            {
                this.View.message = "Error " + ex.Message;
            }
        }
    }
}
